﻿namespace WebPacker.Tests.Configuration
{
	using NUnit.Framework;
	using NXml.Serialization;
	using WebPacker.Configuration;
	using WebPacker.Filters;
	using WebPacker.Providers;

	[TestFixture]
	public class WebPackerTypeResolverTest
	{
		[Test]
		public void ResolveFilterTest(
			[Values("yuiCssMinifier", "WebPacker.Filters.YuiCssMinifier", "WebPacker.Filters.YuiCssMinifier, WebPacker")]
			string typeName)
		{
			var resolver = new WebPackerTypeResolver();
			var expected = typeof(YuiCssMinifier);
			var actual = resolver.ResolveTypeName(typeof(IFilter), typeName);
			Assert.AreEqual(expected, actual);
		}

		[Test]
		public void ResolveFilterErrorTest(
			[Values("YUICSSMinifier", "WebPacker.Filters.YUICSSMinifier, WebPacker")]
			string typeName)
		{
			var resolver = new WebPackerTypeResolver();
			var expected = typeof(YuiCssMinifier);

			Assert.Throws<XmlSerializeException>(() =>
			{
				resolver.ResolveTypeName(typeof(IFilter), typeName);
			});
		}

		[Test]
		public void ResolvePackProviderTest(
			[Values("memoryPackProvider", "memory", "WebPacker.Providers.MemoryPackProvider", "WebPacker.Providers.MemoryPackProvider, WebPacker")]
			string typeName)
		{
			var resolver = new WebPackerTypeResolver();
			var expected = typeof(MemoryPackProvider);
			var actual = resolver.ResolveTypeName(typeof(IPackProvider), typeName);
			Assert.AreEqual(expected, actual);
		}
	}
}
